package cn.edu.qzuie.artist.module.td.dal.mysql.submitactivity;

import java.util.*;

import cn.edu.qzuie.artist.framework.common.pojo.PageParam;
import cn.edu.qzuie.artist.framework.common.pojo.PageResult;
import cn.edu.qzuie.artist.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.edu.qzuie.artist.framework.mybatis.core.mapper.BaseMapperX;
import cn.edu.qzuie.artist.module.td.controller.admin.participateactivitiy.vo.ParticipateActivitiyPageReqVO;
import cn.edu.qzuie.artist.module.td.controller.admin.participateactivitiy.vo.ParticipateActivitiyPagesRespVO;
import cn.edu.qzuie.artist.module.td.dal.dataobject.activity.ActivityDO;
import cn.edu.qzuie.artist.module.td.dal.dataobject.participateactivitiy.ParticipateActivitiyDO;
import cn.edu.qzuie.artist.module.td.dal.dataobject.submitactivity.SubmitActivityDO;
import cn.edu.qzuie.artist.module.td.dal.dataobject.work.WorkDO;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.ibatis.annotations.Mapper;
import cn.edu.qzuie.artist.module.td.controller.admin.submitactivity.vo.*;

/**
 * 投稿 Mapper
 *
 * @author 泉信管理员
 */
@Mapper
public interface SubmitActivityMapper extends BaseMapperX<SubmitActivityDO> {

    default PageResult<SubmitActivityDO> selectPage(SubmitActivityPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SubmitActivityDO>()
                .eqIfPresent(SubmitActivityDO::getStudentId, reqVO.getStudentId())
                .eqIfPresent(SubmitActivityDO::getActivityId, reqVO.getActivityId())
                .eqIfPresent(SubmitActivityDO::getWorkId, reqVO.getWorkId())
                .orderByDesc(SubmitActivityDO::getId));
    }

    default PageResult<SubmitActivityPagesRespVO> selectPageWithName(PageParam pageParam,SubmitActivityPageReqVO reqVO) {
        // 构建查询条件
        MPJLambdaWrapper<SubmitActivityDO> wrapper = new MPJLambdaWrapper<>();

        // 查询 td_submit_activity 表的所有字段
        wrapper.selectAll(SubmitActivityDO.class)
                // 查询
                .select(ActivityDO::getActivityName, ActivityDO::getId)
                .select(WorkDO::getWorkName, WorkDO::getId)
                .leftJoin(ActivityDO.class, ActivityDO::getId, SubmitActivityDO::getActivityId)
                .leftJoin(WorkDO.class, WorkDO::getId, SubmitActivityDO::getWorkId);
        // 动态拼接查询条件
        if (reqVO.getActivityId() != null) {
            wrapper.eq(SubmitActivityDO::getActivityId, reqVO.getActivityId()); // 精确匹配分类 ID
        }
        if (reqVO.getStudentId() != null) {
            wrapper.eq(SubmitActivityDO::getStudentId, reqVO.getStudentId()); // 精确匹配学生 ID
        }
        if (reqVO.getWorkId() != null ) {
            wrapper.eq(SubmitActivityDO::getWorkId, reqVO.getWorkId()); // 精确匹配作品 ID
        }

        // 执行查询并返回结果
        return selectJoinPage(pageParam, SubmitActivityPagesRespVO.class, wrapper);
    }
}